import Global from "../../Global";
import BaseView from "../../components/BaseView";

export default class HomeView extends BaseView{
    private bg
    private bt_signin
    constructor(w?:number,h?:number){
        super(w,h)
        const lib=Global.getLibrary()
        this.bg=new lib.HomeBG();
        let rect=this.bg.getBounds()
        const top=(this.height-rect.height)/2
        this.bg.setTransform(0,top)
        this.addChild(this.bg)
        rect=this.bg.fence.getBounds()
        this.bg.fence.setTransform(0,this.height-top-rect.height)
        //签到按钮
        const bt_signin=new lib.SignInButton()
        bt_signin.setTransform(22,650)
        this.addChild(bt_signin)
        this.bt_signin=bt_signin
        //
        wx.onTouchStart(this.onTouchStart.bind(this))
        //bgm
        const audio=this.getResource('home_bgm') as HTMLAudioElement
        audio.loop=true
        audio.currentTime=0
        audio.play()
    }
    private onTouchStart(res:any):void{
        //console.log(res)
        const {clientX,clientY}=res.touches[0]
        const x=clientX/Global.scale
        const y=clientY/Global.scale
        const bt_signin=this.bt_signin
        const rect=bt_signin.getBounds()
        if(x>bt_signin.x&&y>bt_signin.y&&x<(bt_signin.x+rect.width)&&y<(bt_signin.y+rect.height)){
            //点中bt_signin
            this.dispatchEvent('signin')
        }
    }
    reflush(): void {
        //throw new Error("Method not implemented.");
    }
    
}